package cal

import (
	"encoding/json"
	"fmt"
)

type Teacher struct {
	Name string
	Age  int
	Job  string
}

func main() {
	var tea Teacher = Teacher{
		Name: "mmm",
		Age:  11,
		Job:  "ninin",
	}
	marshal, _ := json.Marshal(&tea)
	fmt.Println(string(marshal))

}

func JsonChange(t Teacher) string {
	fmt.Println(json.Marshal(t))
	marshal, _ := json.Marshal(t)
	return string(marshal)
}

func JsonUnmarshal(t []byte) Teacher {
	var teacher Teacher
	fmt.Println(json.Unmarshal(t, &teacher))
	err := json.Unmarshal(t, &teacher)
	if err != nil {
		fmt.Printf("反序列化错误: %v\n", err)
		return Teacher{} // 返回空对象
	}
	return teacher
}
